package com.LearnInWorld.search.controller;

import com.LearnInWorld.entity.Result;
import com.LearnInWorld.entity.StatusCode;
import com.LearnInWorld.search.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class EsManagerController {


    @Autowired
    private ESManagerService esService;

    @GetMapping("/create")
    public Result createIndexMapping(){
        esService.createIndexMapping();
        return new Result(true, StatusCode.OK,"创建索引成功");
    }

    @GetMapping("/importAll")
    public Result importAll(){
        esService.importAll();
        return new Result(true, StatusCode.OK,"全部导入索引数据成功");
    }

    @GetMapping("/import/{videoId}")
    public Result importDataToEsByVideoId(@PathVariable("videoId")String videoId){
        esService.importDataToEsByVideoId(videoId);
        return new Result(true,StatusCode.OK,"导入索引数据成功");
    }

}
